"""
劳动关系学院-书生镜像 图书封面拷贝
"""
import os
import sys
sys.path.insert(0, os.path.dirname(os.getcwd()))
import shutil
import utils


def copy_cover():

    srcroot = r'\\192.168.0.74\样例数据\sursen\shushengbook_cover_20160729'
    dstroot = r'C:\Users\vente\Desktop\shusheng_cover'
    results = set()
    with open("./list_shusheng.txt") as target:
        for line in target:
            _, id_, _ = line.split(",")
            results.add(id_)
    cnt = 0
    for file, fullpath in utils.file_list(srcroot):
        basename, _, ext = file.partition('.')
        cnt += 1
        if cnt % 1000 == 1:
            print(cnt)
        if basename in results:
            dst_dir = os.path.join(dstroot, file[0])
            if not os.path.exists(dst_dir):
                os.makedirs(dst_dir)
            dst_file = os.path.join(dst_dir, file)
            shutil.copyfile(fullpath, dst_file)


def diff_cover():
    cover_path = r'E:\vendetter\project\python\work\download\ldgx_shusheng\cover\20171103'
    total = set()
    partion = set()
    for file, fullpath in utils.file_list(cover_path):
        id_, _, _ = file.partition('.')
        total.add(id_)
    with open('./cover.txt', encoding='utf8') as f:
        for line in f:
            partion.add(line.strip())
    union = total - partion
    print(union)


if __name__ == '__main__':
    diff_cover()